<template>
	<view>
		<!-- <u-navbar :is-back="true" :is-fixed="true" title="黑名单"></u-navbar> -->
		<!-- <scroll-view scroll-y scroll-with-animation style="height: calc(100vh - 50px);" :show-scrollbar="false"> -->
		<view class="mt-3 pl-2 pr-2">
			<view v-for="(item, itemIndex) in tabContents" :key="itemIndex">
				<view class="u-line pb-2 mt-1" @click="getDiClick(item.id)">
					<view class="dfex">
						<view>{{ item.enterpriseName }}</view>
						<view>{{ item.updateTime.slice(0, 10) }}</view>
					</view>
					<view class="mt-2 text-999999 font-12">{{item.enterprisesReason}}</view>
				</view>
			</view>
		</view>
		<view v-if="!hasMore && tabContents.length > 0" class="text-center mt-3 mb-3">
			<view class="text-muted">没有更多数据了</view>
		</view>
		<view v-else-if="!hasMore && tabContents.length === 0" class="text-center mt-3 mb-3">
			<view class="text-muted">暂无数据</view>
		</view>
		<view v-else class="text-center mt-3 mb-3">
			<view class="btn btn-primary">加载更多</view>
		</view>
		<!-- </scroll-view> -->
	</view>
</template>

<script>
	import $H from "@/common/free-lib/request.js";

	export default {
		data() {
			return {
				tabContents: [],
				form: {
					pageNo: 1,
					pageSize: 10,
					total: 0 // 总页数
				},
				hasMore: true, // 是否还有更多数据
			};
		},

		onLoad() {
			this.getBlackList();
		},
		onReachBottom() {
			if (this.form.pageNo * this.form.pageSize >= this.form.total) {
				this.hasMore = false;
				return;
			}
			this.form.pageNo++;
			this.getBlackList();
		},
		onPullDownRefresh() {
			this.tabContents = [];
			this.form.pageNo = 1;
			this.getBlackList();
		},
		methods: {
			open(path) {
				uni.navigateTo({
					url: "/pages/" + path,
				});
			},
			getBlackList() {
				uni.showLoading({
					title: "加载中"
				})
				$H.get(
						"/agriculture/blacklist/visitor/list", {
							...this.form
						}, {token: false}
					)
					.then((res) => {
						uni.hideLoading();
						uni.stopPullDownRefresh();
						if (res.result.records.length == 0) {
							uni.showToast({
								title: "没有更多啦！",
								icon: "success",
							});
							return;
						}
						const list = [];
						for (let i = 0; i < res.result.records.length; i++) {
							list.push({
								id: res.result.records[i].id,
								enterpriseName: res.result.records[i].enterpriseName,
								updateTime: res.result.records[i].updateTime,
								enterprisesReason: res.result.records[i].enterprisesReason,
							});
						}

						this.tabContents.push(...list);
						this.form.total = res.result.total;
						this.hasMore = this.tabContents.length < this.form.total;
					})
					.catch((error) => {
						uni.hideLoading();
						uni.stopPullDownRefresh();
						console.error("请求出错", error); // 处理任何错误
					});
			},
			getDiClick(id) {
				uni.navigateTo({
					url: "/pages/touristMode/Blacklist/blacklistDi?id=" + id,
				});
			},
		},
	};
</script>

<style>
</style>